home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / win_os2.swg / 0044_4 GB Data - 32 Bit! - Windows.pas < prev    next >
Pascal/Delphi Source File  |  1994-11-30  |  2KB  |  87 lines

  1. { I made a small ASM-routine for accessing 4 GB data in 4 instructions: }
  2.  
  3. PROGRAM test32; {Works for TPW1.5}
  4. {$R-}
  5. {Wim Smit 4-9-1994
  6. Thanx to Jimmy Athens!}
  7. USES WinTypes,WinProcs,WinCrt;
  8. TYPE
  9.     word_array = ARRAY[0..0] OF WORD;
  10.     Pword_array = ^word_array;
  11.  
  12. VAR P:PWORD_Array;
  13.     H:THandle;
  14.     sub1,sub2, 
  15.     segt: WORD;
  16.     i,
  17.     ofst: LONGINT;
  18. BEGIN
  19. WRITELN('BEGIN');
  20.  
  21. h := GlobalAlloc(GMEM_MOVEABLE OR GMEM_SHARE,2*70000);
  22. IF (h = 0) THEN
  23.     Halt;
  24. P := GlobalLock(h);
  25. IF (P = NIL) THEN
  26.     Halt;
  27.  
  28. segt := SEG(p^);
  29. FOR i := 0 TO 69999 DO           {fill the words with their index}
  30.     BEGIN
  31.     ASM
  32.         mov es,segt
  33.         db 66h                   {66h for 386 opcode}              
  34.         mov bx, WORD(i)          {WORD() to fool Pascal}
  35.         db 66h
  36.         shl bx,1                 {ebx times 2: WORDs}
  37.         db 66h
  38.         mov ax, WORD(i)
  39.         db 26h
  40.         db 67h
  41.         db 89h
  42.         db 03h                   {these produce: mov  es:[ebx],ax}
  43.     END;{asm}
  44.     END;{i}
  45. {Now test it by reading the words:}
  46. FOR i := 32762 to 32770 DO       {read over a segment-boundary}
  47.     BEGIN
  48.     ASM
  49.         mov es,segt
  50.         db 66h
  51.         mov bx, WORD(i)          {= mov ebx, i}
  52.         db 66h
  53.         shl bx,1                 {times 2: we're indexing WORDs}
  54.         db 26h
  55.         db 67h
  56.         db 8bh
  57.         db 03h                   {= mov ax, es:[ebx]}
  58.         mov sub2, ax
  59.     END;{asm}
  60.     sub1 := p^[i];
  61.     WRITELN(i:3,':',sub2,' ',sub1);
  62.     END;{i}
  63.  
  64. GlobalUnlock(h);
  65. GlobalFree(h);
  66. WRITELN('DONE');
  67. END.
  68.  
  69. {
  70. Run the program and see the difference:
  71. BEGIN
  72. 32762:32762 32762
  73. 32763:32763 32763
  74. 32764:32764 32764
  75. 32765:32765 32765
  76. 32766:32766 32766
  77. 32767:32767 32767
  78. 32768:32768 0      <-Here 16 bit index will wraparound to p^[0]!
  79. 32769:32769 1
  80. 32770:32770 2
  81. DONE
  82.  
  83. Thus, by choosing the right db's, one can access huge arrays of bytes,
  84. words and longints etc.
  85. Isn't that great?
  86. OK, it needs a 386 or better, but don't we all have that?
  87. }